﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;
using ShredTheLog.Api.DataContracts;
using ShredTheLog.Api;
using System.ComponentModel.Composition;

namespace ShredTheLog.Converters
{
    public sealed class TranslateRequestConverter : ConverterBase, IMultiValueConverter
    {
        [Import]
        private IShredServices ShredServices { get; set; }

        [Import]
        private IUiSettingsSection UiSettings { get; set; }

        public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (values != null && values.Length == 3 && values[0] is string)
            {
                var text = (string)values[0];
                var sourceLanguage = values[1] is Language ? (Language?)values[1] : (Language?)null;
                var targetLanguage = values[2] is Language ? (Language)values[2] : UiSettings.UiLanguage;
                return new TranslateRequest(text, sourceLanguage, targetLanguage, null);
            }
            else
                throw new NotSupportedException();
        }

        public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotSupportedException();
        }

        public static readonly TranslateRequestConverter Default = new TranslateRequestConverter();
    }
}
